/**
 * @file GenConstant.cpp
 *
 *  @date 17 jan 2012
 *  @author Calle Olsen
 *
 *  @brief File for Generate constants
 */

#include <stdlib.h>
#include <Generator/Exp/GenConstant.h>
#include <AbsSyn/BoolExp.h>
#include <AbsSyn/IntExp.h>
#include <AbsSyn/DoubleExp.h>
#include <Generator/GenExp.h>
#include <Interfaces/IGenExp.h>

GenConstant::~GenConstant() {

}

GenConstant::GenConstant(TypeEnum Type, const ExpRegistry& expRegistry):
		m_Registry(expRegistry),
		m_Type(Type)
{
}



AbsSyn::IExpPtr GenConstant::genConstant() const
{
	AbsSyn::IExpPtr shrdPtr;
	ExpRegistry::TGenFunTypeMap typeGenMap;


	if( m_Registry.getAll(TerminalState::TERMINAL,typeGenMap) )
	{
		ExpRegistry::TGenFunTypeMap::const_iterator iter;

		// We need to convert the Type to whatever expression type
		// that fit the type.
		ExpressionType expType = TypeEnum::getConstantExpressionType(m_Type);

		//Now find the expression type from the expression registry.
		iter = typeGenMap.find(expType);
		if(iter != typeGenMap.end() )
		{
			ExpRegistry::TGenPtr genPtr = (*iter).second;

			GenExp::GenExpPtr genExpPtr; //This is null, no need for it
			shrdPtr = genPtr->genExp(genExpPtr);

			std::cout << "Generating constant " << iter->first.toString() << std::endl;
			assert(shrdPtr);
		}

	}


	return shrdPtr;
}


